/*   1:    */ package com.atomikos.icatch.imp;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeurCommitException;
/*   4:    */ import com.atomikos.icatch.HeurHazardException;
/*   5:    */ import com.atomikos.icatch.HeurMixedException;
/*   6:    */ import com.atomikos.icatch.HeurRollbackException;
/*   7:    */ import com.atomikos.icatch.HeuristicMessage;
/*   8:    */ import com.atomikos.icatch.Participant;
/*   9:    */ import com.atomikos.icatch.RollbackException;
/*  10:    */ import com.atomikos.icatch.SysException;
/*  11:    */ import com.atomikos.icatch.TxState;
/*  12:    */ import com.atomikos.icatch.imp.thread.InterruptedExceptionHelper;
/*  13:    */ import java.util.Enumeration;
/*  14:    */ import java.util.Hashtable;
/*  15:    */ import java.util.Stack;
/*  16:    */ 
/*  17:    */ class HeurMixedStateHandler
/*  18:    */   extends CoordinatorStateHandler
/*  19:    */ {
/*  20:    */   private Hashtable hazards_;
/*  21:    */   
/*  22:    */   HeurMixedStateHandler(CoordinatorImp coordinator)
/*  23:    */   {
/*  24: 55 */     super(coordinator);
/*  25: 56 */     this.hazards_ = new Hashtable();
/*  26:    */   }
/*  27:    */   
/*  28:    */   HeurMixedStateHandler(CoordinatorStateHandler previous, Hashtable hazards)
/*  29:    */   {
/*  30: 62 */     super(previous);
/*  31: 63 */     this.hazards_ = ((Hashtable)hazards.clone());
/*  32:    */   }
/*  33:    */   
/*  34:    */   protected Object getState()
/*  35:    */   {
/*  36: 68 */     return TxState.HEUR_MIXED;
/*  37:    */   }
/*  38:    */   
/*  39:    */   protected void onTimeout()
/*  40:    */   {
/*  41: 76 */     boolean committed = getCommitted().booleanValue();
/*  42:    */     
/*  43:    */ 
/*  44: 79 */     addAllForReplay(this.hazards_.keySet());
/*  45:    */     
/*  46: 81 */     Stack replayStack = getReplayStack();
/*  47: 82 */     boolean replay = false;
/*  48: 83 */     if (!replayStack.empty())
/*  49:    */     {
/*  50: 84 */       replay = true;
/*  51: 85 */       int count = replayStack.size();
/*  52: 86 */       TerminationResult result = new TerminationResult(count);
/*  53: 88 */       while (!replayStack.empty())
/*  54:    */       {
/*  55: 89 */         Participant part = (Participant)replayStack.pop();
/*  56: 90 */         if (committed)
/*  57:    */         {
/*  58: 91 */           CommitMessage cm = new CommitMessage(part, result, false);
/*  59: 92 */           getPropagator().submitPropagationMessage(cm);
/*  60:    */         }
/*  61:    */         else
/*  62:    */         {
/*  63: 94 */           RollbackMessage rm = new RollbackMessage(part, result, true);
/*  64:    */           
/*  65: 96 */           getPropagator().submitPropagationMessage(rm);
/*  66:    */         }
/*  67:    */       }
/*  68:    */       try
/*  69:    */       {
/*  70:100 */         result.waitForReplies();
/*  71:    */         
/*  72:    */ 
/*  73:    */ 
/*  74:    */ 
/*  75:105 */         Stack replies = result.getReplies();
/*  76:    */         
/*  77:107 */         Enumeration enumm = replies.elements();
/*  78:108 */         while (enumm.hasMoreElements())
/*  79:    */         {
/*  80:109 */           Reply reply = (Reply)enumm.nextElement();
/*  81:111 */           if (!reply.hasFailed()) {
/*  82:112 */             this.hazards_.remove(reply.getParticipant());
/*  83:    */           }
/*  84:    */         }
/*  85:116 */         if (this.hazards_.isEmpty())
/*  86:    */         {
/*  87:117 */           TerminatedStateHandler termStateHandler = new TerminatedStateHandler(this);
/*  88:    */           
/*  89:119 */           getCoordinator().setStateHandler(termStateHandler);
/*  90:    */         }
/*  91:120 */         else if (replay)
/*  92:    */         {
/*  93:125 */           getCoordinator().setStateHandler(this);
/*  94:    */         }
/*  95:    */       }
/*  96:    */       catch (InterruptedException inter)
/*  97:    */       {
/*  98:130 */         InterruptedExceptionHelper.handleInterruptedException(inter);
/*  99:    */       }
/* 100:    */     }
/* 101:    */   }
/* 102:    */   
/* 103:    */   protected void setGlobalSiblingCount(int count) {}
/* 104:    */   
/* 105:    */   protected int prepare()
/* 106:    */     throws RollbackException, IllegalStateException, HeurHazardException, HeurMixedException, SysException
/* 107:    */   {
/* 108:155 */     throw new HeurHazardException(getHeuristicMessages());
/* 109:    */   }
/* 110:    */   
/* 111:    */   protected HeuristicMessage[] commit(boolean onePhase)
/* 112:    */     throws HeurRollbackException, HeurMixedException, HeurHazardException, IllegalStateException, RollbackException, SysException
/* 113:    */   {
/* 114:164 */     throw new HeurMixedException(getHeuristicMessages());
/* 115:    */   }
/* 116:    */   
/* 117:    */   protected HeuristicMessage[] rollback()
/* 118:    */     throws HeurCommitException, HeurMixedException, SysException, HeurHazardException, IllegalStateException
/* 119:    */   {
/* 120:172 */     throw new HeurMixedException(getHeuristicMessages());
/* 121:    */   }
/* 122:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.imp.HeurMixedStateHandler
 * JD-Core Version:    0.7.0.1
 */